package com.example.bill.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class YearMonthAdapter extends BaseAdapter {
    private final Context context;
    private final DateTimeFormatter dateTimeFormatter;

    public YearMonthAdapter(Context context) {
        this.context = context;
        dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
    }

    @Override
    public int getCount() {
        return 20;
    }

    @Override
    public LocalDate getItem(int position) {
        return LocalDate.now().minusMonths(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView result;
        if (convertView == null) {

            result = new TextView(context);

            result.setPadding(10, 10, 10, 10);
        } else {
            result = (TextView) convertView;
        }
        result.setText(dateTimeFormatter.format(getItem(position)));

        return result;
    }
}
